import EventBus from '../EventBus'
import store from '@/store'
function getLowCode() {
  return store.state.lowCode
}
const listConfig = {
  prev: {
    name: '上一步',
    type: 'prev',
    icon: 'undo',
    disabled: () => getLowCode().snapshotIndex === getLowCode().snapshotMinIndex,
    onClick: (vueObj) => {
      EventBus.$emit('snapshotPrev')
    },
  },
  next: {
    name: '下一步',
    type: 'next',
    icon: 'redo',
    disabled: () => getLowCode().snapshotList.length === getLowCode().snapshotIndex + 1,
    onClick: () => {
      EventBus.$emit('snapshotNext')
    },
  },
  deleteAll: {
    name: '清空画布',
    type: 'deleteAll',
    icon: 'deleteAll',
    // disabled: () => !(getLowCode().snapshotIndex > getLowCode().snapshotMinIndex && getLowCode().snapshotList[getLowCode().snapshotIndex].length > 0),
    disabled: () => getLowCode().canvasComponentList.length === 0,
    onClick: () => {
      EventBus.$emit('deleteAll')
    },
  },
  reset: {
    name: '重置画布',
    type: 'reset',
    icon: 'reset',
    disabled: () => getLowCode().snapshotList.length === 0,
    onClick: () => {
      EventBus.$emit('reset')
    },
  },
  delete: {
    name: '删除',
    type: 'delete',
    icon: 'delete',
    disabled: () => getLowCode().multipleKeys.length === 0,
    onClick: () => {
      EventBus.$emit('delectSelectedComponent')
    },
  },
  topping: {
    name: '置顶',
    type: 'topping',
    icon: 'vertical-align-top',
    disabled: () => !getLowCode().selectedComponent.key,
    onClick: () => {
      EventBus.$emit('toppingSelectedComponent')
    },
  },
  setAtEnd: {
    name: '置底',
    type: 'setAtEnd',
    icon: 'vertical-align-bottom',
    disabled: () => !getLowCode().selectedComponent.key,
    onClick: () => {
      EventBus.$emit('setAtEndSelectedComponent')
    },
  },
  cancel: {
    name: '关闭菜单',
    type: 'cancel',
    icon: 'close',
    disabled: () => false,
    onClick: () => {
      EventBus.$emit('cancelSelectedComponent')
    },
  },
  save: {
    name: '保存',
    type: 'save',
    icon: 'save',
    disabled: () => getLowCode().snapshotList.length === 0,
    onClick: () => {
      EventBus.$emit('save')
    },
  },
  saveAs: {
    name: '另存为',
    type: 'saveAs',
    icon: 'save',
    disabled: () => getLowCode().snapshotList.length === 0,
    onClick: () => {
      EventBus.$emit('saveAs')
    },
  },
  preview: {
    name: '预览',
    type: 'preview',
    icon: 'preview',
    disabled: () => false, // getLowCode().previewData.componentList.length === 0,
    onClick: () => {
      EventBus.$emit('preview')
    },
  },
  copy: {
    name: '复制',
    type: 'copy',
    icon: 'copy',
    disabled: () => getLowCode().multipleKeys.length === 0,
    onClick: () => {
      EventBus.$emit('copy')
    },
  },
  paste: {
    name: '粘贴',
    type: 'paste',
    icon: 'snippets',
    disabled: () => getLowCode().clipboardData.length === 0,
    onClick: () => {
      EventBus.$emit('paste')
    },
  },
  shear: {
    name: '剪切',
    type: 'shear',
    icon: 'scissor',
    disabled: () => getLowCode().multipleKeys.length === 0,
    onClick: () => {
      EventBus.$emit('shear')
    },
  },
  dataDetails: {
    name: '数据明细',
    type: 'dataDetails',
    icon: 'ordered-list',
    disabled: () => getLowCode().multipleKeys.length === 0,
    onClick: () => {
      EventBus.$emit('dataDetails')
    },
  },
  editAnalysis: {
    name: '编辑',
    type: 'editAnalysis',
    icon: 'edit',
    disabled: () => getLowCode().multipleKeys.length !== 1,
    onClick: () => {
      EventBus.$emit('editAnalysis')
    },
  },
  cancelList: {
    name: '退出',
    type: 'cancelList',
    icon: 'close',
    disabled: () => false,
    onClick: () => {
      EventBus.$emit('cancelList')
    },
  },
}

export default function getButnList(typeList = [], isHideDisabled) {
  const list = typeList.map((item) => listConfig[item])
  if (isHideDisabled) {
    return list.filter((item) => !item.disabled())
  }
  return list
}
